package com.slicktechnologies.client.views.settings.employee;

import java.util.Vector;

import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.simplesoftwares.client.library.FormField;
import com.simplesoftwares.client.library.FormFieldBuilder;
import com.simplesoftwares.client.library.appstructure.search.Filter;
import com.simplesoftwares.client.library.appstructure.search.MyQuerry;
import com.simplesoftwares.client.library.composite.DateComparator;
import com.simplesoftwares.client.library.composite.PersonInfoComposite;
import com.simplesoftwares.client.library.mywidgets.ObjectListBox;
import com.slicktechnologies.client.utility.AppUtility;
import com.slicktechnologies.client.utility.Screen;
import com.slicktechnologies.client.views.settings.employee.EmployeePresenter.EmployeePresenterSearch;
import com.slicktechnologies.shared.common.businessunitlayer.Branch;
import com.slicktechnologies.shared.common.helperlayer.Config;
import com.slicktechnologies.shared.common.helperlayer.ConfigCategory;
import com.slicktechnologies.shared.common.helperlayer.Type;
import com.slicktechnologies.shared.common.personlayer.Employee;

public class EmployeePresenterSearchProxy extends EmployeePresenterSearch {
	public PersonInfoComposite personInfo;
	public ObjectListBox<Branch> olbBranch;
	
	public ListBox lbStatus;
	public DateComparator dateComparator;
	


	public Object getVarRef(String varName)
	{
		
		return null ;
	}
	public EmployeePresenterSearchProxy()
	{
		super();
		createGui();
	}
	public void initWidget()
	{
		MyQuerry querry=new MyQuerry();
		querry.setQuerryObject(new Employee());
		olbBranch= new ObjectListBox<Branch>();
		AppUtility.makeBranchListBoxLive(olbBranch);
		personInfo=new PersonInfoComposite(querry,false);
		
		
		
		
		lbStatus= new ListBox();
		lbStatus.addItem("--Select--");
		lbStatus.addItem("Active");
		lbStatus.addItem("Inactive");
	}
	public void createScreen()
	{
		initWidget();
		FormFieldBuilder builder;
		builder = new FormFieldBuilder("",personInfo);
		FormField fpersonInfo= builder.setMandatory(false).setRowSpan(1).setColSpan(5).build();
		builder = new FormFieldBuilder("Branch",olbBranch);
		FormField folbBranch= builder.setMandatory(false).setRowSpan(0).setColSpan(0).build();

		
		


	

		builder = new FormFieldBuilder("Status",lbStatus);
		FormField fstatus= builder.setMandatory(false).setRowSpan(0).setColSpan(0).build();



		this.fields=new FormField[][]{
				{fpersonInfo},
				{folbBranch,fstatus},
				
		};
	}
	public MyQuerry getQuerry()
	{
		Vector<Filter> filtervec=new Vector<Filter>();
		Filter temp=null;


		
		
		if(lbStatus.getSelectedIndex()!=0)
		{
			temp=new Filter();
			temp.setQuerryString("status");
			
			String selVal=lbStatus.getItemText(lbStatus.getSelectedIndex());
			if(selVal.equals("Active"))
			{
				temp.setBooleanvalue(true);
			}
			
			else
			{
				temp.setBooleanvalue(false);
			}
			
			filtervec.add(temp);
		}

		
		if(olbBranch.getSelectedIndex()!=0){
			temp=new Filter();temp.setStringValue(olbBranch.getValue().trim());
			temp.setQuerryString("branchName");
			filtervec.add(temp);
		}
		



		{


			if(personInfo.getIdValue()!=-1)
			{  
				temp=new Filter();
				temp.setIntValue(personInfo.getIdValue());
				temp.setQuerryString("count");
				filtervec.add(temp);
			}

			if(!(personInfo.getFullNameValue().equals("")))
			{
				temp=new Filter();
				temp.setStringValue(personInfo.getFullNameValue());
				temp.setQuerryString("fullname");
				filtervec.add(temp);
			}
			if(personInfo.getCellValue()!=-1l)
			{
				temp=new Filter();
				temp.setLongValue(personInfo.getCellValue());
				temp.setQuerryString("contacts.cellNo1");
				filtervec.add(temp);
			}
		}
		MyQuerry querry= new MyQuerry();
		querry.setFilters(filtervec);
		querry.setQuerryObject(new Employee());
		return querry;
	}
}
